package collect

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"collection_srv/collectionclient"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

// @Summary 血糖仪测试数据
// @Description 用户选择设备进行测试
// @Tags 列表展示
// @Accept json
// @Produce json
// @Param data body types.GlucoseRequest true "data"
// @Success 200 {object} types.Response
// @Failure 400 {string} types.Response
// @Router /collection/clucose [post]
type GlucoseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGlucoseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GlucoseLogic {
	return &GlucoseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 血糖仪测试数据
func (l *GlucoseLogic) Glucose(req *types.GlucoseRequest) (resp *types.Response, err error) {
	collection, err := l.svcCtx.Collection.Glucose(l.ctx, &collectionclient.GlucoseRequest{
		UserId:   req.UserId,
		DeviceId: req.DeviceId,
	})
	if err != nil {
		return respons.Error(400, "血糖仪数据测试失败", err.Error()), err
	}
	return respons.Success(collection), nil
}
